<div id="graph-radial" class="graph graph-radial"></div>

<script type="text/javascript">
	var r = <%= width %> / 2;

	var tree = d3.layout.tree()
	    .size([360, r - 140])
	    .separation(function(a, b) { return (a.parent == b.parent ? 1 : 2) / a.depth; });

	var diagonal = d3.svg.diagonal.radial()
	    .projection(function(d) { return [d.y, d.x / 180 * Math.PI]; });

	var vis = d3.select("#graph-radial").append("svg")
	    .attr("width", r * 2)
	    .attr("height", r * 2)
	  .append("g")
	    .attr("transform", "translate(" + r + "," + r + ")");

  var data = JSON.parse('<%= sanitize(data.to_json) -%>');
  var nodes = tree.nodes(data);

  var link = vis.selectAll("path.link")
      .data(tree.links(nodes))
    .enter().append("path")
      .attr("class", "link")
      .attr("d", diagonal);

  var node = vis.selectAll("g.node")
      .data(nodes)
    .enter().append("g")
      .attr("class", "node")
      .attr("transform", function(d) { return "rotate(" + (d.x - 90) + ")translate(" + d.y + ")"; })
      .on("click", function (d) {
            if (d.url) {
              window.location.href = d.url;
            }
          });

  node.append("circle")
      .attr("class", function(d) { return d.health; })
      .attr("r", 3.5);

  node.append("svg:a")
      .append("text")
  		.attr("class", function(d) { return d.release; })
  		.attr("deployment", function(d) { return d.deployment; })
  		.attr("pkg", function(d) { return d.pkg; })
      .attr("dx", function(d) { return d.x < 180 ? 8 : -8; })
      .attr("dy", ".31em")
      .attr("text-anchor", function(d) { return d.x < 180 ? "start" : "end"; })
      .attr("transform", function(d) { return d.x < 180 ? null : "rotate(180)"; })
      .text(function(d) { return d.name; });
</script>
